import request from './request'
import { userAddress } from '@/model/addressModel'

export const searchAddressByUserId = (
  userId: number,
  currentPage: number,
  pageSize: number
) => {
  return request({
    url: 'address',
    method: 'GET',
    params: { userId, currentPage, pageSize }
  })
}

export const searchProvince = () => {
  return request({
    url: 'address/province',
    method: 'GET'
  })
}

export const searchCity = (provinceId: number) => {
  return request({
    url: 'address/city',
    method: 'GET',
    params: { provinceId }
  })
}

export const searchCounty = (cityId: number) => {
  return request({
    url: 'address/county',
    method: 'GET',
    params: { cityId }
  })
}

export const searchWay = (countyId: number) => {
  return request({
    url: 'address/way',
    method: 'GET',
    params: { countyId }
  })
}

export const searchAddress = (wayName: string) => {
  return request({
    url: 'address/search',
    method: 'GET',
    params: { wayName }
  })
}

export const updateAddress = (address: userAddress) => {
  return request({
    url: 'address/update',
    method: 'PUT',
    data: { address }
  })
}

export const insertAddress = (address: userAddress, user_id: number) => {
  return request({
    url: 'address/insert',
    method: 'POST',
    data: { address, user_id }
  })
}

export const deleteAddress = (address_id: number) => {
  return request({
    url: 'address/delete',
    method: 'DELETE',
    params: { address_id }
  })
}
